package com.mapbased.sfw.binding;

import com.mapbased.sfw.component.XmlContext;
import com.mapbased.sfw.model.PathBag;
import com.mapbased.sfw.model.RenderContext;
import com.mapbased.sfw.model.ResBag;
import com.mapbased.sfw.model.Site;

public class Link extends Binding {

	public static final String STAMP_STR="l";
	final String name;
	public Link(String name){
		this.name=name;
	}
	@Override
	public String getValue(RenderContext rc) {
		Site site=rc.getSite();
		PathBag pg=	site.getPathBag(name);
		if(pg instanceof ResBag){
			String rp=site.conf.resPrefix;
			StringBuilder sb=new StringBuilder();
			if(rp!=null){
				sb.append(rp);
			}
			sb.append(name).append("?").append(STAMP_STR).append("=").append(pg.lastModified(rc));
		   return sb.toString();
		   
		}
		
		return name;
	}

	@Override
	public void toXml(XmlContext xc) {
		xc.sb.append("@link{").append(this.name).append("}");

	}

 

}
